package com.base.cn.platform.os.controller.web.user.center.cash;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.common.utils.cashRecord.CashRecordSourceForm;
import com.base.cn.platform.os.service.manage.user.account.CusUserCashRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户提现记录Controller
 *
 * @author s.li
 * @date 2018/12/01
 */
@Controller
@RequestMapping("/web/uc/cash")
public class WebUserCashRecordController extends WebBaseController {

    @Autowired
    private CusUserCashRecordService cusUserCashRecordService;

    /**
     * 保存提现记录
     * @param account 提现的账户
     * @param accountType 提现的类型
     * @param price 提现金额
     * @return Map<String,Object>
     */
    @RequestMapping("/saveCashRecord")
    @ResponseBody
    public Map<String,Object> saveCashRecord(HttpServletRequest request,
                                             @RequestParam("account") String account,
                                             @RequestParam("accountType") int accountType,
                                             @RequestParam("price") int price){
        Map<String,Object> params = new HashMap<>();
        params.put("account",account);
        params.put("accountType",accountType);
        params.put("price",price);
        params.put("sourceForm", CashRecordSourceForm.SOURCE_FORM_PC.getSourceForm());
        params.put("userId",webMobileLoginUtil.getLoginUserId(request));
        return cusUserCashRecordService.createUserCashRecord(params);
    }


    /**
     * 查询用户提现申请记录数据列表
     * @param request HttpServletRequest
     * @param model Model
     * @param condition 查询条件
     * @param currentPage 页码
     * @return 操作页面
     */
    @RequestMapping("/ajaxFindUserCashRecordList")
    public String ajaxFindUserCashRecordList(HttpServletRequest request,
                                             Model model,
                                             @RequestBody Map<String, Object> condition,
                                             @RequestParam(value = "currentPage") int currentPage) {
        condition.put("userId",webMobileLoginUtil.getLoginUserId(request));
        Map<String,Object> dataMap = cusUserCashRecordService.findUserCashRecordListPage(condition,currentPage,10);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/center/myAccount/cash/ajax-cash-record-list");
    }
}